package cn.com.greatwall.common.utils;

import java.math.BigDecimal;
import java.util.Calendar;

/**
 * @Author herw
 * @Time 2021-04-09 09:25:38
 * @Version 1.0
 * @Description: TODO(用一句话描述该文件做什么)
 */
public class TimeUtil {
    public static String msTransToHours(String mills) {
        double mill = Double.parseDouble(mills);
        double hours = mill / (60 * 60 * 1000);
        BigDecimal bg = new BigDecimal(hours);
        return String.valueOf(bg.setScale(4, BigDecimal.ROUND_HALF_UP));
    }

    public static long hoursTransToMiss(int hours) {
        long hour = Long.valueOf(hours);
        return hour * 60 * 60 * 1000;

    }

    public static int tranToMiss(String interval) {
        String units = interval.substring(interval.length() - 1, interval.length());
        int value = Integer.parseInt(interval.substring(0, interval.length() - 1));
        int result = 0;
        switch (units) {
        case "m":
            result = value * 60;
            break;
        case "h":
            result = value * 60 * 60;
            break;
        case "d":
            result = value * 24 * 60 * 60;
            break;
        default:
            ;
        }
        return result;
    }

    public static Calendar nowCalendar() {
        long now = System.currentTimeMillis();
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(now);
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(Calendar.SECOND, 0);
        return cal;
    }
}
